package com.intellagric.controller.agritech.controller;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.common.utils.JsonUtils;
import com.intellagric.module.agritech.AgtSpeciesVo;
import com.intellagric.pojo.AgtSpecies;
import com.intellagric.service.agritech.SpeciesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: cwq
 * @Date: 2019/2/21 15:31
 * @Description:
 */
@RequestMapping("/api/agt_species")
@Controller
public class SpeciesController {

    @Autowired
    private SpeciesService speciesService;

    @RequestMapping("/add")
    @ResponseBody
    public ResponseMessage add(AgtSpecies species) {
        return speciesService.addSpecies(species);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return speciesService.deleteSpecies(id);
    }

    @RequestMapping("/edit")
    @ResponseBody
    public ResponseMessage edit(AgtSpecies species) {
        return speciesService.editSpecies(species);
    }

    @RequestMapping("/{id}")
    @ResponseBody
    public AgtSpecies get(@PathVariable String id) {
        return speciesService.getSpeciesById(id);
    }

    @RequestMapping("/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return speciesService.getSpeciesTree();
    }

/*    @RequestMapping("/child/{id}")
    @ResponseBody
    public LayuiDataGridResult getCate(@PathVariable String id) {
        return speciesService.getChild(id)
    }*/

    @RequestMapping("/tree/select")
    @ResponseBody
    public String getTreeSelect() {
        String data = JsonUtils.objectToJson(speciesService.getSpeciesTree().getData());
        return data.replaceAll("speciesName", "name");
    }

    @RequestMapping("/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return speciesService.getSpeciesList();
    }

    @RequestMapping("/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(AgtSpeciesVo agtSpeciesVo, int page, int limit) {
        return speciesService.getSpeciesListByVo(agtSpeciesVo, page, limit);
    }

    @RequestMapping("/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return speciesService.getSpeciesByPage(page, limit);
    }
}
